/*
 * Fram.h
 *
 *  Created on: Jul 11, 2021
 *      Author: tau
 */

#ifndef DRV_FRAM_H_
#define DRV_FRAM_H_
#include "gpio.h"



//WREN Set Write Enable Latch 0000 0110B
//WRDI Reset Write Enable Latch 0000 0100B
//RDSR Read Status Register 0000 0101B
//WRSR Write Status Register 0000 0001B
//READ Read Memory Code 0000 0011B
//WRITE Write Memory Code 0000 0010B
//RDID Read Device ID 1001 1111B


typedef enum{
	fWREN = 0x06,
	fWRDI = 0x04,
	fRDSR = 0x05,
	fWRSR = 0x01,
	fREAD = 0x03,
	fWRITE = 0x02,
	fRDID = 0x9f,
}opCode_e;

class Fram {
private:
//	gpio* __cs;
	gpio* __wp;
	gpio* __hold;
	void config(char val);
	void sendCmd(opCode_e cmd);
public:
	Fram(int wpPinIndex,int holePinIndex);
	virtual ~Fram();
	void readID(char* idBuffer);
	void readMem(unsigned int  addr,unsigned int  length,char* buffer);
	void writeMem(unsigned int  addr,unsigned int  length,char* buffer);

};

#endif /* DRV_FRAM_H_ */
